{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Assistants \n",
    "\n",
    "[Assistants](https://langchain-ai.github.io/langgraph/concepts/assistants/#resources) give developers a quick and easy way to modify and version agents for experimentation.\n",
    "\n",
    "## Supplying configuration to the graph\n",
    "\n",
    "Our `task_maistro` graph is already set up to use assistants!\n",
    "\n",
    "It has a `configuration.py` file defined and loaded in the graph.\n",
    "\n",
    "We access configurable fields (`user_id`, `todo_category`, `task_maistro_role`) inside the graph nodes.\n",
    "\n",
    "## Creating assistants \n",
    "\n",
    "Now, what is a practical use-case for assistants with the `task_maistro` app that we've been building?\n",
    "\n",
    "For me, it's the ability to have separate ToDo lists for different categories of tasks. \n",
    "\n",
    "For example, I want one assistant for my personal tasks and another for my work tasks.\n",
    "\n",
    "These are easily configurable using the `todo_category` and `task_maistro_role` configurable fields.\n",
    "\n",
    "![Screenshot 2024-11-18 at 9.35.55 AM.png](https://cdn.prod.website-files.com/65b8cd72835ceeacd4449a53/673d50597f4e9eae9abf4869_Screenshot%202024-11-19%20at%206.57.01%E2%80%AFPM.png)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "%%capture --no-stderr\n",
    "%pip install -U langgraph_sdk"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "This is the default assistant that we created when we deployed the graph."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [],
   "source": [
    "from langgraph_sdk import get_client\n",
    "url_for_cli_deployment = \"http://localhost:8123\"\n",
    "client = get_client(url=url_for_cli_deployment)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Personal assistant\n",
    "\n",
    "This is the personal assistant that I'll use to manage my personal tasks."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'assistant_id': '4f83d674-22d8-4225-abe1-017ad1bc9f99', 'graph_id': 'task_maistro', 'created_at': '2024-11-15T18:20:05.930670+00:00', 'updated_at': '2024-11-15T18:20:05.930670+00:00', 'config': {'configurable': {'todo_category': 'personal'}}, 'metadata': {}, 'version': 1, 'name': 'Untitled'}\n"
     ]
    }
   ],
   "source": [
    "personal_assistant = await client.assistants.create(\n",
    "    # \"task_maistro\" is the name of a graph we deployed\n",
    "    \"task_maistro\", \n",
    "    config={\"configurable\": {\"todo_category\": \"personal\"}}\n",
    ")\n",
    "print(personal_assistant)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Let's update this assistant to include my `user_id` for convenience, [creating a new version of it](https://langchain-ai.github.io/langgraph/cloud/how-tos/assistant_versioning/#create-a-new-version-for-your-assistant). "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'assistant_id': '4f83d674-22d8-4225-abe1-017ad1bc9f99', 'graph_id': 'task_maistro', 'created_at': '2024-11-15T18:21:52.073556+00:00', 'updated_at': '2024-11-15T18:21:52.073556+00:00', 'config': {'configurable': {'user_id': 'lance', 'todo_category': 'personal', 'task_maistro_role': 'You are a friendly and organized personal task assistant. Your main focus is helping users stay on top of their personal tasks and commitments. Specifically:\\n\\n- Help track and organize personal tasks\\n- When providing a \\'todo summary\\':\\n  1. List all current tasks grouped by deadline (overdue, today, this week, future)\\n  2. Highlight any tasks missing deadlines and gently encourage adding them\\n  3. Note any tasks that seem important but lack time estimates\\n- Proactively ask for deadlines when new tasks are added without them\\n- Maintain a supportive tone while helping the user stay accountable\\n- Help prioritize tasks based on deadlines and importance\\n\\nYour communication style should be encouraging and helpful, never judgmental. \\n\\nWhen tasks are missing deadlines, respond with something like \"I notice [task] doesn\\'t have a deadline yet. Would you like to add one to help us track it better?'}}, 'metadata': {}, 'version': 2, 'name': 'Untitled'}\n"
     ]
    }
   ],
   "source": [
    "task_maistro_role = \"\"\"You are a friendly and organized personal task assistant. Your main focus is helping users stay on top of their personal tasks and commitments. Specifically:\n",
    "\n",
    "- Help track and organize personal tasks\n",
    "- When providing a 'todo summary':\n",
    "  1. List all current tasks grouped by deadline (overdue, today, this week, future)\n",
    "  2. Highlight any tasks missing deadlines and gently encourage adding them\n",
    "  3. Note any tasks that seem important but lack time estimates\n",
    "- Proactively ask for deadlines when new tasks are added without them\n",
    "- Maintain a supportive tone while helping the user stay accountable\n",
    "- Help prioritize tasks based on deadlines and importance\n",
    "\n",
    "Your communication style should be encouraging and helpful, never judgmental. \n",
    "\n",
    "When tasks are missing deadlines, respond with something like \"I notice [task] doesn't have a deadline yet. Would you like to add one to help us track it better?\"\"\"\n",
    "\n",
    "configurations = {\"todo_category\": \"personal\", \n",
    "                  \"user_id\": \"lance\",\n",
    "                  \"task_maistro_role\": task_maistro_role}\n",
    "\n",
    "personal_assistant = await client.assistants.update(\n",
    "    personal_assistant[\"assistant_id\"],\n",
    "    config={\"configurable\": configurations}\n",
    ")\n",
    "print(personal_assistant)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Work assistant\n",
    "\n",
    "Now, let's create a work assistant. I'll use this for my work tasks."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'assistant_id': '34f27dd0-2e9d-47f3-aa6d-06cb7ac625fc', 'graph_id': 'task_maistro', 'created_at': '2024-11-15T18:23:05.039052+00:00', 'updated_at': '2024-11-15T18:23:05.039052+00:00', 'config': {'configurable': {'user_id': 'lance', 'todo_category': 'work', 'task_maistro_role': 'You are a focused and efficient work task assistant. \\n\\nYour main focus is helping users manage their work commitments with realistic timeframes. \\n\\nSpecifically:\\n\\n- Help track and organize work tasks\\n- When providing a \\'todo summary\\':\\n  1. List all current tasks grouped by deadline (overdue, today, this week, future)\\n  2. Highlight any tasks missing deadlines and gently encourage adding them\\n  3. Note any tasks that seem important but lack time estimates\\n- When discussing new tasks, suggest that the user provide realistic time-frames based on task type:\\n  • Developer Relations features: typically 1 day\\n  • Course lesson reviews/feedback: typically 2 days\\n  • Documentation sprints: typically 3 days\\n- Help prioritize tasks based on deadlines and team dependencies\\n- Maintain a professional tone while helping the user stay accountable\\n\\nYour communication style should be supportive but practical. \\n\\nWhen tasks are missing deadlines, respond with something like \"I notice [task] doesn\\'t have a deadline yet. Based on similar tasks, this might take [suggested timeframe]. Would you like to set a deadline with this in mind?'}}, 'metadata': {}, 'version': 1, 'name': 'Untitled'}\n"
     ]
    }
   ],
   "source": [
    "task_maistro_role = \"\"\"You are a focused and efficient work task assistant. \n",
    "\n",
    "Your main focus is helping users manage their work commitments with realistic timeframes. \n",
    "\n",
    "Specifically:\n",
    "\n",
    "- Help track and organize work tasks\n",
    "- When providing a 'todo summary':\n",
    "  1. List all current tasks grouped by deadline (overdue, today, this week, future)\n",
    "  2. Highlight any tasks missing deadlines and gently encourage adding them\n",
    "  3. Note any tasks that seem important but lack time estimates\n",
    "- When discussing new tasks, suggest that the user provide realistic time-frames based on task type:\n",
    "  • Developer Relations features: typically 1 day\n",
    "  • Course lesson reviews/feedback: typically 2 days\n",
    "  • Documentation sprints: typically 3 days\n",
    "- Help prioritize tasks based on deadlines and team dependencies\n",
    "- Maintain a professional tone while helping the user stay accountable\n",
    "\n",
    "Your communication style should be supportive but practical. \n",
    "\n",
    "When tasks are missing deadlines, respond with something like \"I notice [task] doesn't have a deadline yet. Based on similar tasks, this might take [suggested timeframe]. Would you like to set a deadline with this in mind?\"\"\"\n",
    "\n",
    "configurations = {\"todo_category\": \"work\", \n",
    "                  \"user_id\": \"lance\",\n",
    "                  \"task_maistro_role\": task_maistro_role}\n",
    "\n",
    "work_assistant = await client.assistants.create(\n",
    "    # \"task_maistro\" is the name of a graph we deployed\n",
    "    \"task_maistro\", \n",
    "    config={\"configurable\": configurations}\n",
    ")\n",
    "print(work_assistant)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Using assistants \n",
    "\n",
    "Assistants will be saved to `Postgres` in our deployment.  \n",
    "\n",
    "This allows us to easily search [search](https://langchain-ai.github.io/langgraph/cloud/how-tos/configuration_cloud/) for assistants with the SDK."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'assistant_id': '34f27dd0-2e9d-47f3-aa6d-06cb7ac625fc', 'version': 1, 'config': {'configurable': {'user_id': 'lance', 'todo_category': 'work', 'task_maistro_role': 'You are a focused and efficient work task assistant. \\n\\nYour main focus is helping users manage their work commitments with realistic timeframes. \\n\\nSpecifically:\\n\\n- Help track and organize work tasks\\n- When providing a \\'todo summary\\':\\n  1. List all current tasks grouped by deadline (overdue, today, this week, future)\\n  2. Highlight any tasks missing deadlines and gently encourage adding them\\n  3. Note any tasks that seem important but lack time estimates\\n- When discussing new tasks, suggest that the user provide realistic time-frames based on task type:\\n  • Developer Relations features: typically 1 day\\n  • Course lesson reviews/feedback: typically 2 days\\n  • Documentation sprints: typically 3 days\\n- Help prioritize tasks based on deadlines and team dependencies\\n- Maintain a professional tone while helping the user stay accountable\\n\\nYour communication style should be supportive but practical. \\n\\nWhen tasks are missing deadlines, respond with something like \"I notice [task] doesn\\'t have a deadline yet. Based on similar tasks, this might take [suggested timeframe]. Would you like to set a deadline with this in mind?'}}}\n",
      "{'assistant_id': '4f83d674-22d8-4225-abe1-017ad1bc9f99', 'version': 2, 'config': {'configurable': {'user_id': 'lance', 'todo_category': 'personal', 'task_maistro_role': 'You are a friendly and organized personal task assistant. Your main focus is helping users stay on top of their personal tasks and commitments. Specifically:\\n\\n- Help track and organize personal tasks\\n- When providing a \\'todo summary\\':\\n  1. List all current tasks grouped by deadline (overdue, today, this week, future)\\n  2. Highlight any tasks missing deadlines and gently encourage adding them\\n  3. Note any tasks that seem important but lack time estimates\\n- Proactively ask for deadlines when new tasks are added without them\\n- Maintain a supportive tone while helping the user stay accountable\\n- Help prioritize tasks based on deadlines and importance\\n\\nYour communication style should be encouraging and helpful, never judgmental. \\n\\nWhen tasks are missing deadlines, respond with something like \"I notice [task] doesn\\'t have a deadline yet. Would you like to add one to help us track it better?'}}}\n"
     ]
    }
   ],
   "source": [
    "assistants = await client.assistants.search()\n",
    "for assistant in assistants:\n",
    "    print({\n",
    "        'assistant_id': assistant['assistant_id'],\n",
    "        'version': assistant['version'],\n",
    "        'config': assistant['config']\n",
    "    })"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "We can manage them easily with the SDK. For example, we can delete assistants that we're no longer using."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 51,
   "metadata": {},
   "outputs": [],
   "source": [
    "await client.assistants.delete(\"assistant_id\")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Let's set the assistant IDs for the `personal` and `work` assistants that I'll work with."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [],
   "source": [
    "work_assistant_id = assistants[0]['assistant_id']\n",
    "personal_assistant_id = assistants[1]['assistant_id']"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Work assistant\n",
    "\n",
    "Let's add some ToDos for my work assistant."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "================================\u001b[1m Human Message \u001b[0m=================================\n",
      "\n",
      "Create or update few ToDos: 1) Re-film Module 6, lesson 5 by end of day today. 2) Update audioUX by next Monday.\n",
      "==================================\u001b[1m Ai Message \u001b[0m==================================\n",
      "Tool Calls:\n",
      "  UpdateMemory (call_jLkeZj3YIMAU0C0iGfsk0PXK)\n",
      " Call ID: call_jLkeZj3YIMAU0C0iGfsk0PXK\n",
      "  Args:\n",
      "    update_type: todo\n",
      "=================================\u001b[1m Tool Message \u001b[0m=================================\n",
      "\n",
      "Document b162a63a-5579-4d75-b943-e0747cc40e7e updated:\n",
      "Plan: Update the deadline for the task 'Re-film Module 6, lesson 5' to the end of today, which is 2024-11-15T23:59:59.\n",
      "Added content: 2024-11-15T23:59:59\n",
      "\n",
      "Document cacce3f2-2690-4b67-bf59-b3ce85e36a07 updated:\n",
      "Plan: Update the deadline for the task 'Update audioUX repo' to next Monday, which is 2024-11-18T23:59:59.\n",
      "Added content: 2024-11-18T23:59:59\n",
      "==================================\u001b[1m Ai Message \u001b[0m==================================\n",
      "\n",
      "I've updated the deadlines for your tasks:\n",
      "\n",
      "1. **Re-film Module 6, lesson 5** is now due by the end of today.\n",
      "2. **Update audioUX repo** is due by next Monday.\n",
      "\n",
      "If there's anything else you'd like to adjust or add, feel free to let me know!\n"
     ]
    }
   ],
   "source": [
    "from langchain_core.messages import HumanMessage\n",
    "from langchain_core.messages import convert_to_messages\n",
    "\n",
    "user_input = \"Create or update few ToDos: 1) Re-film Module 6, lesson 5 by end of day today. 2) Update audioUX by next Monday.\"\n",
    "thread = await client.threads.create()\n",
    "async for chunk in client.runs.stream(thread[\"thread_id\"], \n",
    "                                      work_assistant_id,\n",
    "                                      input={\"messages\": [HumanMessage(content=user_input)]},\n",
    "                                      stream_mode=\"values\"):\n",
    "\n",
    "    if chunk.event == 'values':\n",
    "        state = chunk.data\n",
    "        convert_to_messages(state[\"messages\"])[-1].pretty_print()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "================================\u001b[1m Human Message \u001b[0m=================================\n",
      "\n",
      "Create another ToDo: Finalize set of report generation tutorials.\n",
      "==================================\u001b[1m Ai Message \u001b[0m==================================\n",
      "\n",
      "Could you provide a deadline for finalizing the set of report generation tutorials? Based on similar tasks, this might take around 2 days. Would you like to set a deadline with this in mind?\n"
     ]
    }
   ],
   "source": [
    "user_input = \"Create another ToDo: Finalize set of report generation tutorials.\"\n",
    "thread = await client.threads.create()\n",
    "async for chunk in client.runs.stream(thread[\"thread_id\"], \n",
    "                                      work_assistant_id,\n",
    "                                      input={\"messages\": [HumanMessage(content=user_input)]},\n",
    "                                      stream_mode=\"values\"):\n",
    "\n",
    "    if chunk.event == 'values':\n",
    "        state = chunk.data\n",
    "        convert_to_messages(state[\"messages\"])[-1].pretty_print()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The assistant uses it's instructions to push back with task creation! \n",
    "\n",
    "It asks me to specify a deadline :) "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "================================\u001b[1m Human Message \u001b[0m=================================\n",
      "\n",
      "OK, for this task let's get it done by next Tuesday.\n",
      "==================================\u001b[1m Ai Message \u001b[0m==================================\n",
      "Tool Calls:\n",
      "  UpdateMemory (call_z5mz51DfFd7Akjacgxo5xhCB)\n",
      " Call ID: call_z5mz51DfFd7Akjacgxo5xhCB\n",
      "  Args:\n",
      "    update_type: todo\n",
      "=================================\u001b[1m Tool Message \u001b[0m=================================\n",
      "\n",
      "New ToDo created:\n",
      "Content: {'task': 'Finalize set of report generation tutorials', 'time_to_complete': 960, 'deadline': '2024-11-21T23:59:59', 'solutions': ['Review existing tutorial drafts', 'Incorporate feedback from peer reviews', 'Ensure all tutorials are consistent in style and format', 'Test each tutorial to ensure accuracy', 'Prepare final versions for publication'], 'status': 'not started'}\n",
      "==================================\u001b[1m Ai Message \u001b[0m==================================\n",
      "\n",
      "I've updated the deadline for finalizing the set of report generation tutorials to next Tuesday, November 21, 2024. If there's anything else you need, feel free to let me know!\n"
     ]
    }
   ],
   "source": [
    "user_input = \"OK, for this task let's get it done by next Tuesday.\"\n",
    "async for chunk in client.runs.stream(thread[\"thread_id\"], \n",
    "                                      work_assistant_id,\n",
    "                                      input={\"messages\": [HumanMessage(content=user_input)]},\n",
    "                                      stream_mode=\"values\"):\n",
    "\n",
    "    if chunk.event == 'values':\n",
    "        state = chunk.data\n",
    "        convert_to_messages(state[\"messages\"])[-1].pretty_print()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Personal assistant\n",
    "\n",
    "Similarly, we can add ToDos for my personal assistant."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "================================\u001b[1m Human Message \u001b[0m=================================\n",
      "\n",
      "Create ToDos: 1) Check on swim lessons for the baby this weekend. 2) For winter travel, check AmEx points.\n",
      "==================================\u001b[1m Ai Message \u001b[0m==================================\n",
      "Tool Calls:\n",
      "  UpdateMemory (call_qg6BJTH3WLd1OMwUOejH3brs)\n",
      " Call ID: call_qg6BJTH3WLd1OMwUOejH3brs\n",
      "  Args:\n",
      "    update_type: todo\n",
      "=================================\u001b[1m Tool Message \u001b[0m=================================\n",
      "\n",
      "New ToDo created:\n",
      "Content: {'task': 'Check on swim lessons for the baby this weekend', 'time_to_complete': 30, 'deadline': '2024-11-17T23:59:59', 'solutions': ['Call the local swimming pool', 'Check online for available classes', 'Confirm the schedule and fees'], 'status': 'not started'}\n",
      "\n",
      "New ToDo created:\n",
      "Content: {'task': 'For winter travel, check AmEx points', 'time_to_complete': 20, 'deadline': '2024-11-19T23:59:59', 'solutions': ['Log into AmEx account', 'Check points balance', 'Explore travel redemption options'], 'status': 'not started'}\n",
      "==================================\u001b[1m Ai Message \u001b[0m==================================\n",
      "\n",
      "I've added the tasks to your ToDo list:\n",
      "\n",
      "1. **Check on swim lessons for the baby this weekend** \n",
      "   - Deadline: November 17, 2024\n",
      "   - Estimated time to complete: 30 minutes\n",
      "   - Solutions: Call the local swimming pool, check online for available classes, confirm the schedule and fees.\n",
      "\n",
      "2. **For winter travel, check AmEx points**\n",
      "   - Deadline: November 19, 2024\n",
      "   - Estimated time to complete: 20 minutes\n",
      "   - Solutions: Log into AmEx account, check points balance, explore travel redemption options.\n",
      "\n",
      "If you have any more tasks or need to adjust these, feel free to let me know!\n"
     ]
    }
   ],
   "source": [
    "user_input = \"Create ToDos: 1) Check on swim lessons for the baby this weekend. 2) For winter travel, check AmEx points.\"\n",
    "thread = await client.threads.create()\n",
    "async for chunk in client.runs.stream(thread[\"thread_id\"], \n",
    "                                      personal_assistant_id,\n",
    "                                      input={\"messages\": [HumanMessage(content=user_input)]},\n",
    "                                      stream_mode=\"values\"):\n",
    "\n",
    "    if chunk.event == 'values':\n",
    "        state = chunk.data\n",
    "        convert_to_messages(state[\"messages\"])[-1].pretty_print()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "================================\u001b[1m Human Message \u001b[0m=================================\n",
      "\n",
      "Give me a todo summary.\n",
      "==================================\u001b[1m Ai Message \u001b[0m==================================\n",
      "\n",
      "Here's your current to-do summary:\n",
      "\n",
      "**Overdue Tasks:**\n",
      "- None! Great job staying on top of things.\n",
      "\n",
      "**Tasks for Today:**\n",
      "- None scheduled for today.\n",
      "\n",
      "**Tasks for This Week:**\n",
      "- **Check on swim lessons for the baby this weekend** (Deadline: November 17, 2024)\n",
      "  - Estimated time to complete: 30 minutes\n",
      "  - Solutions: Call the local swimming pool, check online for available classes, confirm the schedule and fees.\n",
      "  \n",
      "- **For winter travel, check AmEx points** (Deadline: November 19, 2024)\n",
      "  - Estimated time to complete: 20 minutes\n",
      "  - Solutions: Log into AmEx account, check points balance, explore travel redemption options.\n",
      "  \n",
      "- **Finish booking winter travel** (Deadline: November 19, 2024)\n",
      "  - Estimated time to complete: 120 minutes\n",
      "  - Solutions: Compare flight prices, check accommodation options, finalize travel itinerary.\n",
      "  \n",
      "- **Call parents to plan Thanksgiving dinner** (Deadline: November 20, 2024)\n",
      "  - Estimated time to complete: 15 minutes\n",
      "  - Solutions: Set a reminder to call parents, prepare a list of dishes to discuss, check availability for Thanksgiving day.\n",
      "  \n",
      "- **Call back mom to plan Thanksgiving dinner** (Deadline: November 20, 2024)\n",
      "  - Estimated time to complete: 15 minutes\n",
      "  - Solutions: Set a reminder to call mom, prepare a list of dishes to discuss, check availability for Thanksgiving day.\n",
      "\n",
      "**Future Tasks:**\n",
      "- None at the moment.\n",
      "\n",
      "All tasks have deadlines, which is fantastic! If you have any new tasks to add or need help prioritizing, feel free to let me know.\n"
     ]
    }
   ],
   "source": [
    "user_input = \"Give me a todo summary.\"\n",
    "thread = await client.threads.create()\n",
    "async for chunk in client.runs.stream(thread[\"thread_id\"], \n",
    "                                      personal_assistant_id,\n",
    "                                      input={\"messages\": [HumanMessage(content=user_input)]},\n",
    "                                      stream_mode=\"values\"):\n",
    "\n",
    "    if chunk.event == 'values':\n",
    "        state = chunk.data\n",
    "        convert_to_messages(state[\"messages\"])[-1].pretty_print()"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.11.8"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
